/**
 * 1
 *  
 * @Author : Ruoyu Wang
 * @DateTime : 24-9-14 下午2:26
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    int nums[n];
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
    }

    long long f[n + 1];
    f[0] = 0;
    for (int i = 1; i <= n; ++i) {
        f[i] = f[i - 1] + min(nums[i - 1], a);
        if (i >= 30) {
            f[i] = min(f[i], f[i - 30] + b);
        }
        if (i >= 365) {
            f[i] = min(f[i], f[i - 365] + c);
        }
        if (i >= 3650) {
            f[i] = min(f[i], f[i - 3650] + d);
        }
    }

    cout << f[n];

    return 0;
}